﻿/// <reference path="jquery-1.8.2.min.js" />
/// <reference path="jquery-easyui-1.3.2/easyloader.js" />
easyloader.locale = "zh_CN"; // 本地化设置
easyloader.css = false; //不引用css文件，引用一个全局的easyui.css，其他样式都自定义
$(function () {
    /*注册自定义tabs事件 start*/
    $.each($(".tabspanel"), function (i, n) {
        $(this).children(".tabscontentpanel").children(".tabcontent").hide().first().show();
        $(this).children(".customtabs").find("li").click(function () {
            $(this).siblings(".selected").removeClass("selected");
            $(this).addClass("selected");
            $(this).closest(".tabspanel").children(".tabscontentpanel").children(".tabcontent").hide().eq($(this).closest("li").index()).show();
        }).first().addClass("selected");
    });
    /*注册自定义tabs事件 end*/

    $("#btngjsearch").click(function () {/*高级搜索按钮的点击事件*/
        var _height = $("#advancedsearchdiv").height();
        if (_height <= 0) {
            $("#advancedsearchdiv").animate({ height: "76px", "padding-top": "10px", "border-top-width": "1px" }, 500);
        }
        else {
            $("#advancedsearchdiv").animate({ height: "0px", "padding-top": "0px", "border-top-width": "0px" }, 500);
        }
    });

    easyloader.load(['combobox', 'dialog', 'datagrid'], function () {
        $(".myeasyui-combobox").combobox();
        $("#dlg").dialog({ /*注册弹出框*/
            resizable: true,
            width: 400,
            height: 200,
            closed: true,
            cache: false,
            buttons: [{
                text: '确定',
                handler: function () {
                    $("#dlg").dialog("close");
                }
            }, {
                text: '关闭',
                handler: function () {
                    $("#dlg").dialog("close");
                }
            }]
        });

        $("#dlgtabs").dialog({/*注册弹出框*/
            resizable: true,
            width: 750,
            height: 300,
            closed: true,
            cache: false
        });

        $("#sdatatab").datagrid({
            data: udata,
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'id', title: 'id', width: 50, align: 'center', sortable: true },
                { field: 'sname', title: '名称', width: 100, align: 'center', sortable: true, formatter: formatterdata },
                { field: 'sarea', title: '地区', width: 100, align: 'center', sortable: true },
                { field: 'scate', title: '项目类型', width: 100, align: 'center', sortable: true, formatter: formatterdata },
                { field: 'sprice', title: '单价', width: 100, align: 'center', sortable: true },
                { field: 'stel', title: '电话', width: 100, align: 'center' },
                { field: 'snote', title: '备注', width: 100, align: 'center', formatter: formatterdata },
                { field: 'Column7', title: '超链接列', width: 100, align: 'center' },
                { field: 'Column8', title: '日期字段', width: 100, align: 'center' }
            ]],
            pagination: true, /*是否显示分页栏*/
            pagePosition: "bottom", /*分页栏的位置*/
            sortname: "id", /*默认排序的列*/
            sortorder: "asc", /*desc*/
            multiSort: true, /*是否启用多列排序*/
            remoteSort: false, /*定义是否是从服务器排序*/
            pageSize: 10, /*每页显示条数*/
            autoRowHeight: false, /*是否自适应行高*/
            fitColumns: true, /*是否自适应列宽*/
            rownumbers: false, /*是否显示行号*/
            singleSelect: false, /*是否单选(一次只选中一行)*/
            /*loadData: udata 读取本地数据,*/
            loadFilter: pagerFilter, /*过滤数据*/
            striped: true /*是否启用隔行渐变*/
        });
    });

    $("#btnfzdialog").click(function () {
        $("#dlgtabs").dialog("open");
    });
    $("#btnsearch").click(function () {
        $("#dlg").dialog({ title: "对话框", content: "搜索" }).dialog("open");
    });
    $("#funcicondiv .btnicon").click(function () {
        $("#dlg").dialog({ title: "对话框", content: $(this).find(".btntxt").text() }).dialog("open");
    });

    $(window).resize(function () {
        var title1 = $("#worktabs").children(".customtabs").outerHeight(true);
        $("#worktabs").children(".tabscontentpanel").css({ width: $(window).width() - 15, height: $(window).height() - title1 - 2 });
        var ss = $("#worktabs").children(".customtabs").height() - $("#datatabdiv").outerHeight(true) - $("#funcicondiv").outerHeight(true) - $("#funcicondiv").next(".panel.datagrid").outerHeight(true) - 10;
        $("#formtabs").children(".tabscontentpanel").css({ height: ss > 200 ? ss : 200 });
        setTimeout(function () {
            var sheight = 291;
            if ($.browser.msie && ($.browser.version == "7.0" || $.browser.version == "6.0")) {
                sheight = 300;
            }
            $("#sdatatab").datagrid('resize', {
                width: $("#datatabdiv").width(),
                height: sheight
            });
            ss = $("#worktabs").children(".tabscontentpanel").height() - $("#formtabs").children(".customtabs").outerHeight(true) - $("#datatabdiv").outerHeight(true) - $("#funcicondiv").outerHeight(true) - $("#funcicondiv").next(".panel.datagrid").outerHeight(true) - 10;
            $("#formtabs").children(".tabscontentpanel").css({ height: ss > 200 ? ss - 8 : 200 });
        }, 300);
    });
    $(window).triggerHandler("resize");
});

function formatterdata(value, row, index) {
    var datalength = 10;
    if (value && value.length > 10) {
        return value.substring(0, datalength) + "...";
    }
    return value;
}

function pagerFilter(data) { /*本地化数据的过滤，只有过滤以后的本地数据才可分行*/
    if (data && typeof data.length == 'number') {    // is array
        data = {
            total: data.length,
            rows: data
        }
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
        onSelectPage: function (pageNum, pageSize) {
            opts.pageNumber = pageNum;
            opts.pageSize = pageSize;
            pager.pagination('refresh', {
                pageNumber: pageNum,
                pageSize: pageSize
            });
            dg.datagrid('loadData', data);
        }
    });
    if (!data.originalRows) {
        //data.originalRows = (data.rows);
        data.originalRows = [];
        data.originalRows = (data.rows);
    }
    var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
    var end = start + parseInt(opts.pageSize);
    data.rows = (data.originalRows.slice(start, end));
    return data;
}

function getData() { /*构造本地数据*/
    var rows = [];
    for (var i = 1; i <= 800; i++) {
        var amount = Math.floor(Math.random() * 1000);
        var price = Math.floor(Math.random() * 1000);
        rows.push({
            inv: 'Inv No ' + i,
            date: $.fn.datebox.defaults.formatter(new Date()),
            name: 'Name ' + i,
            amount: amount,
            price: price,
            cost: amount * price,
            note: 'Note ' + i
        });
    }
    return rows;
}

var udata = [{ "id": 1, "sname": "京翰发射点发生点分散方式", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息各种信息各种信息各种信息各种信息各种信息各种信息各种信息各种信息各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 2, "sname": "京翰上海", "sarea": "上海", "scate": "计算机过热和人蝴蝶飞过三的个", "stel": "12580", "sprice": 150, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 3, "sname": "京翰1", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 130, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 4, "sname": "京翰32", "sarea": "北京", "scate": "计算机高浮雕贵定师范过的发三个三的", "stel": "12580", "sprice": 160, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 5, "sname": "京翰反对法撒个我隔热日和二和人", "sarea": "上海", "scate": "1to1", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 6, "sname": "京翰8", "sarea": "北京", "scate": "1to1", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 7, "sname": "京翰0", "sarea": "北京", "scate": "1to1", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 8, "sname": "京翰", "sarea": "上海", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 9, "sname": "京翰", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 10, "sname": "京翰", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 11, "sname": "京翰", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 12, "sname": "京翰", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 13, "sname": "京翰", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 14, "sname": "京翰", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 15, "sname": "京翰上海", "sarea": "上海", "scate": "计算机", "stel": "12580", "sprice": 150, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 16, "sname": "京翰1", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 130, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 17, "sname": "京翰32", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 160, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 18, "sname": "京翰", "sarea": "上海", "scate": "1to1", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 19, "sname": "京翰8", "sarea": "北京", "scate": "1to1", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 20, "sname": "京翰0", "sarea": "北京", "scate": "1to1", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 21, "sname": "京翰", "sarea": "上海", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 22, "sname": "京翰", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" },
{ "id": 23, "sname": "京翰", "sarea": "北京", "scate": "计算机", "stel": "12580", "sprice": 180, "snote": "各种信息", "Column7": "<a href='http://www.baidu.com' target='_blank'>超链接</a>", "Column8": "2013-09-26" }];
